﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using UAXInversionesWeb.logicaNegocio;
namespace UAXInversionesWeb.supervisor
{
    public partial class InformeGananciasPerdidas : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session["identificador"] != null)
            {



                String fechaI = calendario.SelectedDate.ToString("yyyy" + "/" + "MM" + "/" + "dd");
                inicio.Text = fechaI;
               

            }
        }

        protected void calendario2_SelectionChanged(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session["identificador"] != null)
            {


                String fechaF = calendario2.SelectedDate.ToString("yyyy"+"/"+"MM"+"/"+"dd");
                final.Text = fechaF;
                CarteraCliente[] cc = Proxy.obtenerInformeGanaciasPerdidas(fechaF, inicio.Text);
                Cotizaciones[] c = Proxy.getCotizaciones();
                if (cc.Length > 0)
                {

                    mensaje.Text = "";
                    TableRow row;

                    TableCell cell, cell2, cell3, cell4;


                    for (int i = 0; i < cc.Length; i++)
                    {
                        row = new TableRow();
                        if (i % 2 != 0)
                        {
                            row.BackColor = System.Drawing.Color.FromArgb(240, 244, 247);
                        }

                        cell = new TableCell();
                        cell.HorizontalAlign = HorizontalAlign.Left;
                        cell.Text = cc[i].getIdCliente().ToString();
                        row.Cells.Add(cell);

                        cell2 = new TableCell();
                        cell2.Text = cc[i].getEmpresaCotizante();
                        row.Cells.Add(cell2);
                        for (int j = 0; j < c.Length; j++)
                        {
                            if (c[j].getAcronimo().Equals(cc[i].getEmpresaCotizante()))
                            {
                                cell3 = new TableCell();
                                cell3.HorizontalAlign = HorizontalAlign.Right;
                                cell3.Text = c[j].getValorAccion().ToString("N") + " €"; 
                                row.Cells.Add(cell3);

                                cell4 = new TableCell();
                                cell4.HorizontalAlign = HorizontalAlign.Right;
                                
                                Label lab = new Label();
                                
                                if (c[j].getDiferenciaBase() > 0)
                                {
                                    lab.ForeColor = System.Drawing.Color.Green;
                                    lab.Text = c[j].getDiferenciaBase().ToString("N") + " €";
                                }
                                else
                                {
                                    lab.ForeColor = System.Drawing.Color.Red;
                                    lab.Text = c[j].getDiferenciaBase().ToString("N") + " €";
                                }
                                cell4.Text = c[j].getDiferenciaBase().ToString("N") +" €";
                                cell4.Controls.Add(lab);
                                
                                row.Cells.Add(cell4);
                            }
                        }
                        Table1.Rows.Add(row);
                    }
                }
                else
                {
                    mensaje.Text = "No hay clientes";
                }
            }
        }
    }
}
